#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3010;

ll ans;
int n,k,v[N];
ll t[N];
vector<ll> f[N],g[N];
vector<int> w[N];

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in;
	for(int i = 1;i <= n;i++){
		v[i] = in; int x;
		for(int j = 0;j < v[i];j++) w[i].pb(x = in),t[i] += x;
	}f[0].resize(k+1);
	for(int i = 1;i <= n;i++){
		f[i].resize(k+1);
		for(int j = k;j >= v[i];j--)
			f[i][j] = max(f[i-1][j],f[i-1][j-v[i]]+t[i]);
		for(int j = min(v[i]-1,k);j;j--) f[i][j] = f[i-1][j];
	}g[n+1].resize(k+1);
	for(int i = n;i >= 1;i--){
		g[i].resize(k+1);
		for(int j = k;j >= v[i];j--)
			g[i][j] = max(g[i+1][j],g[i+1][j-v[i]]+t[i]);
		for(int j = min(v[i]-1,k);j;j--) g[i][j] = g[i+1][j];
	}
	for(int i = 1;i <= n;i++){
		ll tot = 0;
		for(int s = 1;s <= min(v[i],k);s++){
			tot += w[i][s-1];
			for(int j = 0;j <= k-s;j++)
				ans = max(ans,f[i-1][j]+g[i+1][k-j-s]+tot);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

